@extends('layouts.console_header')

@section('title', '商家待提现列表')

@section('resources')
    @parent
<style>
    .user_list_search{overflow: hidden;margin: 10px 20px;}
    .user_list_search input{float: right;width: 200px;height: 30px;border: 1px solid #000;}
    .user_list_search .user_list_searchbtn{float: right;height: 30px;margin-left: 10px;width: 50px;background-color: #9955c6;color: #fff;border: none;}
    .user_list_search .play_money{float: left;height: 30px;margin-left: 10px;width: 100px;background-color: #9955c6;color: #fff;line-height: 30px;text-align: center;border-radius: 5px;cursor: pointer;}
    .user_list_pageouter{overflow: hidden;background-color: #fff;}
    .user_list_page{float: right;overflow: hidden;}
    .user_list_page a{float: left;width: 40px;height: 30px;line-height: 30px;text-align: center;}
    .user_list_page .show{background-color: #eee;border: 1px solid #ccc;}
    .display{text-align: center;background-color: #fff;border-collapse:collapse;}
    .display th{padding: 20px 0;}
    .display #tbody_content{border-top: 1px solid #000;border-bottom: 1px solid #000;font-size: 14px;}
    .display #tbody_content tr:nth-child(2n+1){border-bottom: 1px solid #ddd;background-color: #f9f9f9;}
    .display #tbody_content tr:nth-child(2n){border-bottom: 1px solid #ddd;}
    .display #tbody_content tr td{padding: 10px 0;}
    .display #tbody_content tr td:nth-child(1){background-color: #f1f1f1;}
    nav{width: 100%;background: rgba(0,0,0,0.3);position: fixed;top: 0;left: 0;display: none;}
    #progressbar{position: absolute;top: 50%;left: 50%;width:200px;height:20px;margin-left: -100px;margin-top: -10px;border-radius: 10px;background-color: #ccc;overflow: hidden;}
    #number{position: absolute;top: 0;left: 0;width: 190px;z-index: 1;text-align: right;border-radius: 10px;height: 20px;}
    #content{height:20px;background:yellow;width: 0;border-radius: 10px;position: absolute;top: 0;left: 0;}
    .failedcount{color: #ff0000;width: 300px;}
    .refresh{width: 100px;height: 30px;background-color: #9955c6;color: #fff;display: inline-block;margin-left: 20px;border-radius: 5px;line-height: 30px;}
    .refresh_mark{width: 100%;text-align: center;font-size: 24px;background: rgba(0,0,0,0.5);display: none;position: fixed;top: 0;color: #fff;}
</style>
@endsection

@section('content')
<p class="refresh_mark">刷新中....</p>
<section class="user_list">
	<div style="border-bottom: 2px solid #9955c6;overflow: hidden;">
		<p class="fz_14 account_title fl" style="border: none;">
		    <span style="color: #7f7f7f;"><a href="/console/index">首页</a>>财务中心></span>
		    <span class="co_violet"><a href="/console/finance/waitmoney/list?cityid={{$cityid}}">商家待提现列表</a></span>
        </p>
		<a href="#"><p class="fr tc back_btn" id="submit_export">导出</p></a>
	</div>
	<table class="finance_top_list">
		<tr>
			<th>待提现笔数</th>
			<th>待提现金额(元)</th>
			<th></th>
		</tr>
		<tr>
			<td>{{$count}}</td>
			<td>{{$shopamount}}</td>
            <td class="failedcount">{{$failedcount}}笔打款失败<a class="refresh" href="#" onclick="refresh()">刷新数据</a></td>
		</tr>
	</table>
    <p class="user_list_search">
        <span class="play_money">打款</span>
        <input class="user_list_searchbtn" type="button" name="submit_search" value="搜索">
        <input type="text" name="search" value="" placeholder="搜索">
    </p>
	<table class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th style="width: 50px;"><input class="all_choose" type="checkbox" name="" value="">全选</th>
                <th>商家名称</th>
                <th style="width: 60px;">商家代码</th>
                <th>持卡人</th>
                <th>银行卡号</th>
                <th style="width: 60px;">银行名称</th>
                <th>开户行所在地</th>
                <th>开户行行名称</th>
                <th>待提现金额(元)</th>
                <th>备注</th>
            </tr>
        </thead>
        <tbody id="tbody_content">
        @foreach($lists as $list)
            <tr>
                <td><input type="checkbox" name="" value="{{$list['shopaccountid']}}"></td>
                <td>{{$list['shopname']}}</td>
                <td>{{$list['shopcode']}}</td>
                <td>{{$list['cardholder']}}</td>
                <td>{{$list['bankcard']}}</td>
                <td>{{$list['bankname']}}</td>
                <td>{{$list['bankprovince'] . $list['bankcity']}}</td>
                <td>{{$list['opencardbank']}}</td>
                <td>{{$list['accountamount']}}</td>
                <td class="failedcount">{{$list['content']}}</td>
            </tr>
        @endforeach
        </tbody>
    </table>
    <div class="user_list_pageouter">
        <p class="user_list_page">
            <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page=1">首页</a>
            @if($lastpage <=5)
                @for($i=1; $i<=$lastpage; $i++)
                    @if($page == $i)
                        <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$i}}" class="show">{{$i}}</a>
                    @else
                        <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$i}}">{{$i}}</a>
                    @endif
                @endfor
            @else
                @if($page>2)
                    <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$page-2}}">{{$page-2}}</a>
                @endif
                @if($page>1)
                    <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$page-1}}">{{$page-1}}</a>
                @endif
                <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$page}}" class="show">{{$page}}</a>
                @if(($page+5)<$lastpage)
                    <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$page+1}}">{{$page+1}}</a>
                    <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$page+2}}">{{$page+2}}</a>
                    <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$page+3}}">{{$page+3}}</a>
                    <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$page+4}}">{{$page+4}}</a>
                    <a href="">....</a>
                    <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$lastpage}}">{{$lastpage}}</a>
                @else
                    @for($i=1; $i<=5;$i++)
                        @if($page+$i<=$lastpage)
                            <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$page+$i}}">{{$page+$i}}</a>
                        @endif
                    @endfor
                @endif
            @endif
            <a href="/console/finance/waitmoney/list?cityid={{$cityid}}&page={{$lastpage}}">末页</a>
        </p>
    </div>
</section>
<nav>
    <div id="progressbar">
        <p id="number"></p>
        <div id="content"></div>
    </div>
</nav>
{{--<ul class="delete">--}}
    {{--<li>--}}
        {{--<span>确认</span>--}}
        {{--<img class="fr" src="{{env('IMAGE_DOMAIN')}}/images/close_p.png" alt="">--}}
    {{--</li>--}}
    {{--<li>导出后状态变为已提现，是否导出？</li>--}}
    {{--<li>--}}
        {{--<button style="background-color: #9955c6;color: #fff;" class="fl" >确定</button>--}}
        {{--<button class="fr">取消</button>--}}
    {{--</li>--}}
{{--</ul>--}}
@endsection

@section('scriptResources')
    @parent
<script>
    var count;
    var authout=[];     //需打款商家id
    var contentwidth = 0;
    var successcoent = 0;
    var errorcoent = 0;
    var cityid = '{{$cityid}}';
    //全选
    $(".all_choose").click(function(){
        if(this.checked){
            $("#tbody_content input").prop("checked",true);
        }else{
            $("#tbody_content input").prop("checked",false);
        }
    })
    //刷新数据
    function refresh(){
        $(".refresh_mark").show();
        $(".refresh_mark").height($(window).height());
        $(".refresh_mark").css("line-height",$(".refresh_mark").height()+"px");
        $.ajax({
            url : '/console/finance/waitmoney/status/refresh',
            data:{cityid:cityid},
            dataType:'json',
            type:'post',
            success:function(data){
                if(data.status == 'success') {
                    window.location.reload();
                } else {
                    alert(data.message);
                    $(".refresh_mark").hide();
                }
            }
        });
    }
    $("nav").height($(window).height());

    $(".play_money").click(function() {
        count = $("#tbody_content input[type='checkbox']:checked").length;
//        for (var i = 0; i < $("#tbody_content input[type='checkbox']").length; i++) {
//            if($("#tbody_content input[type='checkbox']").eq(i).is(":checked") == true){
//                authout.push($("#tbody_content input[type='checkbox']").eq(i).val());
//            }else{
//                continue;
//            }
//        };
//        console.log(authout);
        if(count == 0){
            alert("请选择打款商家！"); return;
        }else{
            $("nav").show();
            $("#number").html(successcoent+"/"+count);
            for (var i = 0; i < count; i++) {
                var shopaccountid=$("input[type='checkbox']:checked").eq(i).val();
                $.ajax({
                    "url":"/console/finance/waitmoney/remit",
                    "dataType":"json",
                    "data":{
                        "shopaccountid":shopaccountid,
                        "cityid":cityid
                        },
                    "type":"post",
                    "async":"true"
                }).success(function(data){
                    successcoent+=1;
                    contentwidth = contentwidth + 200/count;
                    //css用来设置style里面的属性，attr用来设置元素的属性值
                    $("#content").css("width",contentwidth);
                    $("#number").html(successcoent+"/"+count);
                    if((successcoent+errorcoent) == count) {
                        window.location.reload();
                    }
                }).error(function(data){
                    errorcoent+=1;
                    contentwidth = contentwidth + 200/count;
                    //css用来设置style里面的属性，attr用来设置元素的属性值
                    $("#content").css("width",contentwidth);
                    $("#number").html(successcoent+"/"+count);
                    if((successcoent+errorcoent) == count) {
                        window.location.reload();
                    }
                });
            };
        }
    });
    $(document).ready(function(){
        $(".back_btn").click(function(){
            //$(".delete").show();
        })
        $(".delete li img").click(function(){
            //$(".delete").hide();
        })
    })
    $("#submit_export").click(function(){
        var is_confirm = confirm("确定导出？？");
        if(is_confirm) {
            console.log("确定导出");
            window.location.href = '/console/finance/waitmoney/export?cityid=' + cityid;
        }
    });
    $(".user_list_searchbtn").click(function() {
        var search=$("input[name='search']").val();
        if(search == '') {
            return;
        }
        window.location.href = "/console/finance/waitmoney/list?cityid="+cityid+"&search="+search+"&now=" + Date.parse(new Date());
    });
</script>
@endsection